package com.team.cloudsharing.dao.folder;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.team.cloudsharing.dao.file.FileDO;
import com.team.cloudsharing.dao.sharefolder.ShareFolderDO;
import com.team.cloudsharing.dao.user.UserDO;

@Entity
@Table(name = "folder")
public class FolderDO implements Serializable{

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "folder_id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long folderId;
	
	@Column(name = "folder_name", nullable = false)
	private String folderName;
	
	@Column(name = "folder_id_parent", nullable = false)
	private Long folderIdParent;
	
	@Column(name = "folder_path", nullable = false)
	private String folderPath = "";
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_create", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
	private Date dateCreate = new Date();
	
	@Column(name = "folder_url", nullable = false)
	private String folderUrl;
	
	@Column(name = "is_shared_folder", nullable = false)
	private boolean isSharedFolder = false;
	
	@Column(name = "is_folder_in_trash", nullable = false)
	private boolean isFolderInTrash = false;
	
	@Column(name = "folder_permission", nullable = false)
	private Integer folderPermission;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id", nullable = false)
	private UserDO userDO;
	
	@OneToMany(mappedBy = "folderDO", fetch = FetchType.EAGER)
	@Cascade({CascadeType.DELETE, CascadeType.SAVE_UPDATE})
	private Set<FileDO> fileDO;
	
	@OneToMany(mappedBy = "folderDO", fetch = FetchType.EAGER)
	@Cascade({CascadeType.DELETE, CascadeType.SAVE_UPDATE})
	private Set<ShareFolderDO> shareFolderDO;
	
	public FolderDO() {
	}
	
	public FolderDO(String folderName, String folderUrl, long folderIdParent, boolean isSharedFolder,
			boolean isFolderInTrash, Integer folderPermission, UserDO userDO) {
		super();
		this.folderName = folderName;
		this.folderUrl = folderUrl;
		this.folderIdParent = folderIdParent;
		this.isSharedFolder = isSharedFolder;
		this.isFolderInTrash = isFolderInTrash;
		this.folderPermission = folderPermission;
		this.userDO = userDO;
	}

	public Long getFolderId() {
		return folderId;
	}

	public void setFolderId(Long folderId) {
		this.folderId = folderId;
	}

	public String getFolderName() {
		return folderName;
	}

	public void setFolderName(String folderName) {
		this.folderName = folderName;
	}

	public Date getDateCreate() {
		return dateCreate;
	}

	public void setDateCreate(Date dateCreate) {
		this.dateCreate = dateCreate;
	}

	public String getFolderUrl() {
		return folderUrl;
	}

	public void setFolderUrl(String folderUrl) {
		this.folderUrl = folderUrl;
	}

	public boolean isSharedFolder() {
		return isSharedFolder;
	}

	public void setSharedFolder(boolean isSharedFolder) {
		this.isSharedFolder = isSharedFolder;
	}

	public boolean isFolderInTrash() {
		return isFolderInTrash;
	}

	public void setFolderInTrash(boolean isFolderInTrash) {
		this.isFolderInTrash = isFolderInTrash;
	}

	public Integer getFolderPermission() {
		return folderPermission;
	}

	public void setFolderPermission(Integer folderPermission) {
		this.folderPermission = folderPermission;
	}

	public UserDO getUserDO() {
		return userDO;
	}

	public void setUserDO(UserDO userDO) {
		this.userDO = userDO;
	}

	public String getFolderPath() {
		return folderPath;
	}

	public void setFolderPath(String folderPath) {
		this.folderPath = folderPath;
	}

	public Set<FileDO> getFileDO() {
		return fileDO;
	}

	public void setFileDO(Set<FileDO> fileDO) {
		this.fileDO = fileDO;
	}


	public Long getFolderIdParent() {
		return folderIdParent;
	}

	public void setFolderIdParent(Long folderIdParent) {
		this.folderIdParent = folderIdParent;
	}

	public Set<ShareFolderDO> getShareFolderDO() {
		return shareFolderDO;
	}

	public void setShareFolderDO(Set<ShareFolderDO> shareFolderDO) {
		this.shareFolderDO = shareFolderDO;
	}
	
}
